package cn.jinjie.day09;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Test02 {
    public static void main(String[] args) {
        HashMap<String, String> map = new HashMap<>();
        map.put("001", "坏数字");
        map.put("002", "好数字");
        map.put("003", "黑马树哥");
        map.put("004", "黑马树哥1");

        //根据key获取value
        System.out.println(map.get("001"));
        System.out.println(map.get("002"));

        //获取所有的key
        Set<String> list = map.keySet();

        for (String s : list) {
            String s1 = map.get(s);
            System.out.println(s+"=="+s1);
        }
        Collection<String> values = map.values();
        System.out.println(map.values());

        //获取所有的键值对 返回的是一个set集合 集合里面存的是Map.Entry对象
        Set<Map.Entry<String, String>> entries = map.entrySet();

        //遍历set集合
        for (Map.Entry<String, String> entry : entries) {
            String key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key+":"+value);
        }


    }
}
